#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
typedef long long ll;
ll as(ll a, ll b, ll p)
{
    ll ret = 1;
    while (b)
    {
        if (b & 1)
        {
            ret = ret * a % p;
        }
        a = a * a % p;
        b >>= 1;
    }
    return ret;
}
int main()
{
    ll a, b, p;
    cin >> a >> b >> p;
    printf("%lld^%lld mod %lld=%lld", a, b, p, as(a, b, p));
    return 0;
}